<!-- 爬取股票记录列表 -->
<template>
  <div class="DealerInfoStyle">
    <!-- 表格 -->
    <el-table :data="crawlStocksTable" border style="width: 100%;overflow: auto;">
      <el-table-column resizable prop="id" label="id" width="60" align="center">
      </el-table-column>
      <el-table-column resizable prop="stocks_id" label="股票ID" width="auto" min-width="100px" align="center">
      </el-table-column>
      <el-table-column resizable prop="stocks" label="股票名称" width="auto" min-width="200px" align="center">
      </el-table-column>
      <el-table-column resizable prop="name" label="行业名称" width="auto" min-width="200px" align="center">
      </el-table-column>
      <el-table-column resizable prop="content" label="内容" width="auto" min-width="100px" align="center">
      </el-table-column>
      <el-table-column resizable prop="add_time" label="添加时间" width="auto" min-width="170px" align="center">
      </el-table-column>
      <el-table-column resizable prop="is_public" label="是否显示" width="auto" min-width="170px" align="center">
        <template slot-scope="scope">
          <el-switch v-model="scope.row.is_public" :active-value="1" :inactive-value="0"
            @change="handleSwitchChange(scope.row)"></el-switch>
        </template>
      </el-table-column>


    <!-- <el-table-column resizable label="操作" width="150"  align="center">
        <template slot-scope="scope">
          <el-button @click="tableEditing(scope.row)" type="primary" plain size="small">编辑</el-button>
          <el-button @click="del_administratorDelete(scope.row.admin_id)" type="danger" plain size="small">刪除</el-button>
              </template>
                          </el-table-column> -->
    </el-table>

    <!-- 分页 -->
    <div style="text-align: right; margin-top: 5px;">
      <el-pagination background layout="prev, pager, next,total" :total="total" :page-size="pagesize"
        @current-change="current_change"></el-pagination>
    </div>
  </div>
</template>

<script>
import { crawlStockInformation, editCrawlingStocks } from "@/utils/api";
export default {
  name: 'crawlStocksInfo',
  data() {
    return {
      form: {
        admin_name: ''
      },
      crawlStocksTable: [],
      total: 100, //总条数
      pagesize: 10, //指定展示多少条
      currentPage: 1, //当前页码
      titles: '',
      roleHeadgear: null,
      is_public: 0
    };
  },
  mounted() {
    this.get_crawlStockInformation()
  },

  methods: {
    // 查询公司列表
    async get_crawlStockInformation() {
      const res = await crawlStockInformation(this.currentPage).catch((err) => {
        return console.error(err);
      });
      if (res && res.status == "200") {
        this.crawlStocksTable = res.data.data.data
        this.total = res.data.data.total
      } else {
        this.$message.error(res.data.message);
      }
    },
    async DisplaySwitchInterface() {
      const res = await crawlStockInformation(this.currentPage).catch((err) => {
        return console.error(err);
      });
      if (res && res.status == "200") {
        this.$message.success(res.data.message);
        this.crawlStocksTable = res.data.data.data
        this.total = res.data.data.total
      } else {
        this.$message.error(res.data.message);
      }
    },
    async handleSwitchChange(row) {
      const data = {
        id: row.id, // 假设每个数据行有一个 id 字段
        is_public: row.is_public, // 当前开关的状态
      };

      const res = await editCrawlingStocks(data).catch((err) => {
        console.error(err);
        this.$message.error("接口调用失败，请稍后重试！");
      });

      if (res && res.status == "200") {
        this.$message.success(res.data.message);
        this.get_crawlStockInformation()
      } else {
        this.$message.error(res.data.message || "未知错误");
        this.get_crawlStockInformation()
      }
    },
    // 分页
    current_change(currentPage) {
      this.currentPage = currentPage;
      this.get_crawlStockInformation();
    },
  },
};
</script>
<style>
.cell {
  font-size: 12px;
  white-space: nowrap !important;
}

.el-dialog__body {
  padding: 0 10px !important;
}

.demo-table-expand {
  font-size: 0;
  margin-left: 10px;
}

.demo-table-expand label {
  width: 90px;
  color: #99a9bf;
}

.demo-table-expand .el-form-item {
  margin-right: 0;
  margin-bottom: 0;
  width: 50%;
}
</style>
<style lang="less" scoped>
.DealerInfoStyle {
  width: 100%;
  padding: 0 10px;
  // background-color: aquamarine;
  height: calc(100vh - 100px);
  // border: 1px #000 solid;

  .cardAdmin {
    position: relative;
    // height: 18%;
    width: 100%;
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    margin: 0;

    border: #ebeef5 solid 1px;
    padding: 0 5px;
    margin-bottom: 2px;


    .formContainer {
      width: 100%;
      display: flex;
      flex-wrap: wrap;
      padding: 0;
      align-self: baseline;
      padding-bottom: 40px;
    }

    .formSearch {
      width: 25%;
      min-width: 25%;
      margin: 10px 0;
      height: 40px;
      display: flex;
      justify-content: center;
    }
  }

  .pop-up-form {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    padding: 0;
    align-self: baseline;
    margin: 10px 0;
    justify-content: center;
    padding-right: 15px;

    .form-options {
      width: 100%;
      min-width: 100%;
      height: 40px;
      display: flex;
      justify-content: center;
      margin: 10px 0;
    }
  }
}
</style>
